﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SQLite;

namespace Classes
{
   public class Sensor
   {
      #region Private Member Variables

      private String partNumber, location;
      private Boolean existing;
      private int zone;
      private double cost;

      #endregion

      #region Properties

      public String PartNumber   { get { return partNumber; } }
      public String Location     { get { return location; } }
      public Boolean Existing    { get { return existing; } }
      public int Zone            { get { return zone; } }
      public Boolean Upgrade     { get { return cost >= 0; } }
      public Double Cost         { get { return cost; } }
      public String DBString 
      { 
         get 
         { 
            String x = String.Format("{0}/{1}/{2}/{3}", zone, partNumber, location, existing);
            if (Upgrade)
               x += "/" + cost;

            return x;
         }
      }

      #endregion

      #region Constructors

      /// <summary>
      /// Creates a new sensor object based on individual input.
      /// </summary>
      /// <param name="iPart">Part Number</param>
      /// <param name="iLocation">Location of Installation</param>
      /// <param name="iExist">Was the Sensor Already Installed</param>
      /// <param name="iZone">Zone Sensor was programmed into</param>
      /// <param name="iCost">Amount Customer paid for sensor as upgrade</param>
      public Sensor(String iPart, String iLocation, bool iExist,
         int iZone, double iCost)
      {
         partNumber = iPart;
         location = iLocation;
         existing = iExist;
         zone = iZone;
         cost = iCost;
      }

      /// <summary>
      /// Creates a new Sensor object from the single string stored in the database
      /// </summary>
      /// <param name="i">String of paramters for sensor.</param>
      public Sensor(String i)
      {
         String[] info = i.Split( '/' );
         zone = int.Parse(info[0]);
         partNumber = info[1];
         location = info[2];
         existing = bool.Parse(info[3]);
         cost = (info.Length == 5 ? double.Parse(info[4]) : -1);
      }

      #endregion
   }
}
